<template>
  
  <editDialog isText btnText="编辑" btnType="text" title="编辑分组" :loading="isLoading" :submit-loading="isLoading"
    @submit="handleSubmit" @opened="opened">
    <template #btn>
      <Edit style="width: 1.1em; height: 1.1em; margin: 3px 8px 0"  />
    </template>
    <view class="row">
      <view class="row-label">分组名称:</view>
      <el-input class="row-value" v-model="categoryName" placeholder="请输入分组名称"></el-input>
    </view>
  </editDialog>
</template>
<script setup>
  let vk = uni.vk
  import {
    ref
  } from 'vue'
  import editDialog from "/common/components/EditDialog/index"
  import { ElMessage } from 'element-plus'
  let categoryName = ref("")
  let isLoading = ref(false)
  const emits = defineEmits(['success'])
  
  let props =defineProps({
    data: {
      type: Object,
      default: {}
    }
  })
  
  const handleSubmit = async (callback) => {
    if (!categoryName.value) {
      ElMessage.warning("请填写分类名称")
    }
    try {
      isLoading.value = true
      uni.vk.callFunction({
      	url: 'client/uni-id-files/categories/kh/update',
      	title: '请求中...',
      	data: {
      		name: categoryName.value,
          _id: props.data._id
      	},
      	success: (data) => {
          isLoading.value = false
          emits('success')
      		callback()
      	}
      });
    } catch (error) {
      isLoading.value = false
    }
  }
  const opened = () => {
    categoryName.value = props.data.name
  }
</script>

<style lang="scss" scopedn>
  .row {
    display: flex;

    .row-label {
      width: 120px;
    }
  }
</style>